
Imports std
Imports System.IO

Module replaceWF

    Sub Main(ByVal args() As String)
        On Error Resume Next

        If isdebugmode() Then
            pause()
        End If

        If args.Length < 3 Then
            raiseError("argument count error, mappingfile input output, " + _
                        "if input or output is '/-', use console, program will transform backslashes", _
                        errorHandle.errorType.critical)
        Else
            Dim reader As TextReader = Nothing
            Dim words As vector(Of String) = Nothing
            Dim input As String = Nothing
            Dim replacer As vector(Of pair(Of String, String)) = Nothing

            If strsame(args(0), "/-") Then
                reader = Console.In
            Else
                reader = New StreamReader(New FileStream(args(0), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            End If
            replacer = New vector(Of pair(Of String, String))
            input = reader.ReadLine()
            While Not input Is Nothing
                strsepar(input, character.tab, words)
                If words.size() = 2 Then
                    replacer.push_back(make_pair(Of String, String)(words(0), words(1)))
                End If
                input = reader.ReadLine()
            End While
            closestream(reader)
            gainshar.replace(replacer, args(1), args(2))
        End If
    End Sub

End Module
